<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				uId:'',
				replaceCacheKey:"hr-kq-askleave-replaceTile-replace-cache"
			})
		},
		methods:{
			onSelectReplacePos(item){
				let _that = this
				_that.$refs.autoform.formdata.replaceInst = item.instName
			},
			findPosByUserIdAndInstId(userId){
				let _that = this
				_that.om.request(
					"orgInstPosUserOfficial/findPosByUserIdAndInstId",{
						userid: userId,
						instid:'' 
					}
				).then(res=>{
					_that.$refs.autoform.changeEditor("replaceTile","replacePosId","data",configSelectData(res,'id','posname'))
					_that.$refs.autoform.initSelectIndex("replaceTile","replacePosId")
				})
			},
			initLoad(){
				let _that = this
				let pro1 = _that.om.request('orgInstPosUserOfficial/findPosByUserIdAndInstId',{
						userid:_that.uId,
						instid:''
					}
				)
				Promise.all([pro1]).then(res=>{
					_that.$refs.autoform.changeEditor("replaceTile","posId","data",configSelectData(res[0],'id','posname'))
					_that.$refs.autoform.initSelectIndex("replaceTile","posId")
				})
				
			}  
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.replaceCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.replaceId = d.id
							formdata.replaceName = d.username
							_that.findPosByUserIdAndInstId(d.id)
							uni.removeStorage({
								key:_that.replaceCacheKey
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			_that.uId = e.userId
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor("replaceTile","replaceId",{
								link:"../../public/pageSearch/pageSearch",
								'linkParam':{
									other:JSON.stringify({
										filterIdsStr:_that.uId
									}),
									url:"temployee/getStaffCombogrid",
									cachename:_that.replaceCacheKey,
									namefield:"userPosName",
									extrafield:"salaryPosInstName",
									searchfield:"q",
									placeholder:"请输入姓名"
								}
							},null,_that.autoformdata)
							_that.initLoad()
							}
						}
					})
				}
			})
			_that.$nextTick(function(){
				let _that = this
				if(_that.$refs.autoform.formdata.replaceId){
					_that.findPosByUserIdAndInstId(_that.$refs.autoform.formdata.replaceId)
				}
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
